home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
dlgds411.zip
/
CPPRSRC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-06
|
12KB
|
456 lines
#define Uses_TEventQueue
#define Uses_TEvent
#define Uses_TProgram
#define Uses_TApplication
#define Uses_TKeys
#define Uses_TRect
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_TView
#define Uses_TWindow
#define Uses_TFrame
#define Uses_TScroller
#define Uses_TScrollBar
#define Uses_TDialog
#define Uses_TButton
#define Uses_TSItem
#define Uses_TCheckBoxes
#define Uses_TRadioButtons
#define Uses_TLabel
#define Uses_TInputLine
#define Uses_TCollection
#define Uses_THistory
#define Uses_THistoryWindow
#define Uses_TListBox
#define Uses_TStringCollection
#define Uses_TMemo
#define Uses_TColoredText
#define Uses_TInputLong
#define Uses_fpstream
#define Uses_MsgBox
#define Uses_TResourceCollection
#define Uses_TResourceFile
#include <tv.h>
#include <stdlib.h>
#include <dos.h>
#include <dir.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <new.h>
#include "tinplong.h"
#include "tcolortx.h"
#include "readscpt.h"
__link(RView);
__link(RDialog);
__link(RResourceCollection);
__link(RButton);
__link(RCluster);
__link(RCheckBoxes);
__link(RRadioButtons);
__link(RLabel);
__link(RStaticText);
__link(RScrollBar);
__link(RInputLine);
__link(RHistory);
__link(RListBox);
__link(RMemo);
__link(RInputLong);
__link(RColoredText);
TDialog *dlg; //hold the dialog as it is built up
TView *control;
TScrollBar *hScrollBar;
//the following extend the ViewObj struct's to also write the code
struct DialogResourceObj : DialogObj {
virtual void writeCode();
};
struct ButtonResourceObj : ButtonObj {
virtual void writeCode();
};
struct InputLongResourceObj : InputLongObj {
virtual void writeCode();
};
struct LabelResourceObj : LabelObj {
virtual void writeCode();
};
struct HistoryResourceObj : HistoryObj {
virtual void writeCode();
};
struct InputLineResourceObj : InputLineObj {
virtual void writeCode();
};
struct ClusterResourceObj : ClusterObj {
virtual void writeCode();
};
struct ListBoxResourceObj : ListBoxObj {
virtual void writeCode();
};
struct ScrollBarResourceObj : ScrollBarObj {
virtual void writeCode();
};
struct MemoResourceObj : MemoObj {
virtual void writeCode();
};
struct StaticTextResourceObj : StaticTextObj {
virtual void writeCode();
};
struct ColoredTextResourceObj : ColoredTextObj {
virtual void writeCode();
};
char* convert(char *s)
// converts the strings (which are meant to be quoted ascii strings) to
// string suitable for input without quotes. \n (two chars) is converted
// to newline, \" (two chars) is converted to single ", etc.
{
static char rslt[300];
char *d = rslt, c = *s++;
while( c ) {
if (c == '\\') {
if (*s == '\\') {*d++ = '\\'; s++;}
else if (*s == 'n') {*d++ = '\n'; s++;}
else if (*s == '"') {*d++ = '"'; s++;}
}
else *d++ = c;
c = *s++;
}
*d = '\0';
rslt[254] = '\0'; //this is max string len for TStaticText!
return rslt;
}
void reportError(const char* s)
{
cout << s << endl;
exit(1);
}
void doOptionsEtc(TView *P, ViewObj *V)
{
P->options = V->Optns;
P->eventMask = V->EvMsk;
P->helpCtx = V->HCtx;
P->growMode = V->Grow;
}
void DialogResourceObj::writeCode()
{
dlg = new TDialog(TRect(X1, Y1, X2, Y2), convert(Title));
if (dlg) {
doOptionsEtc(dlg, this);
dlg->palette = Palette;
dlg->flags = WinFlags;
}
else reportError("Cannot construct TDialog");
}
void ButtonResourceObj::writeCode()
{
control = new TButton(TRect(X1, Y1, X2, Y2), convert(ButtonText),
CommandValue, Flags);
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TButton");
}
void InputLongResourceObj::writeCode()
{
control = new TInputLong(TRect(X1, Y1, X2, Y2), LongStrLeng, LLim, ULim,
ILOptions, convert(LongLabelText));
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TInputLong");
}
void InputLineResourceObj::writeCode()
{
control = new TInputLine(TRect(X1, Y1, X2, Y2), StringLeng);
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TInputLine");
}
void StaticTextResourceObj::writeCode()
{
control = new TStaticText(TRect(X1, Y1, X2, Y2), convert(Text));
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TStaticText");
}
void ColoredTextResourceObj::writeCode()
{
control = new TColoredText(TRect(X1, Y1, X2, Y2), convert(Text), Attrib);
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TColoredText");
}
void ScrollBarResourceObj::writeCode()
{
TScrollBar *tmp = new TScrollBar(TRect(X1, Y1, X2, Y2));
if (tmp) {
doOptionsEtc(tmp, this);
dlg->insert(tmp);
if (stricmp(VarName, "hscroll") == 0)
hScrollBar = tmp; // probably a horizontal scroll bar for TMemo
else control = tmp;
}
else reportError("Cannot construct TScrollBar");
}
void ListBoxResourceObj::writeCode()
{
TScrollBar *scroll = 0;
if (ScrollBar != 0)
scroll = (TScrollBar*)control;
control = new TListBox(TRect(X1, Y1, X2, Y2), Columns, scroll);
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TListBox");
}
void MemoResourceObj::writeCode()
{
TScrollBar *vbar = 0, *hbar = 0;
if (VScroll != 0)
vbar = (TScrollBar*)control;
if (HScroll != 0)
hbar = hScrollBar;
control = new TMemo(TRect(X1, Y1, X2, Y2), hbar, vbar, 0, BufSize);
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else reportError("Cannot construct TMemo");
}
void formTSItem(void *p, void* l)
{char *s = (char*)p;
TSItem *last = new TSItem(newStr(convert(s)), *(TSItem**)l);
*(TSItem**)l = last;
}
void ClusterResourceObj::writeCode()
{
TSItem *lastItem = 0;
// LabelColl->forEach(&formTSItem, &lastItem);
for (int i=Items-1; i >= 0; i--) { //must do this one backwards
char *s = (char *)LabelColl->at(i);
lastItem = new TSItem(convert(s), lastItem);
}
if (strcmp(Obj, "TCheckBoxes") == 0)
control = new TCheckBoxes(TRect(X1, Y1, X2, Y2), lastItem);
else if (strcmp(Obj, "TRadioButtons") == 0)
control = new TRadioButtons(TRect(X1, Y1, X2, Y2), lastItem);
else control = 0;
if (control) {
doOptionsEtc(control, this);
dlg->insert(control);
}
else {
cout << "Cannot construct " << Obj << endl;
exit(1);
}
}
void LabelResourceObj::writeCode()
{
TLabel *labl = new TLabel(TRect(X1, Y1, X2, Y2), convert(LabelText), control);
if (labl) {
doOptionsEtc(labl, this);
dlg->insert(labl);
}
else reportError("Cannot construct TLabel");
}
void HistoryResourceObj::writeCode()
{
THistory *history = new THistory(TRect(X1, Y1, X2, Y2), (TInputLine*)control,
HistoryID);
if (history) {
doOptionsEtc(history, this);
dlg->insert(history);
}
else reportError("Cannot construct THistory");
}
//now that we know the final extensions of ViewObj, we can write the
//getKind function
ViewObj *getKind(recType Kind)
{ ViewObj *P;
switch (Kind) {
case Dlg : P = new DialogResourceObj(); break;
case Button : P = new ButtonResourceObj(); break;
case InputL : P = new InputLineResourceObj(); break;
case Labl : P = new LabelResourceObj(); break;
case Histry : P = new HistoryResourceObj(); break;
case ILong : P = new InputLongResourceObj(); break;
case CheckB: P = new ClusterResourceObj(); break;
case RadioB: P = new ClusterResourceObj(); break;
case MultiCB: P = new MultiCheckBoxObj(); break;